import { get, post, put, del } from '@/utils/request'
import type { Announcement, AnnouncementParams } from '@/types/announcement'
import type { Result, PageResult } from '@/types/common'
import { postFormData } from "../utils/request"

// 获取公告列表
export function getAnnouncementList(params: AnnouncementParams): Promise<Result<PageResult<Announcement>>> {
  return get<Result<PageResult<Announcement>>>('/announcements/list', params)
}

// 获取公告详情
export function getAnnouncementDetail(id: number): Promise<Result<Announcement>> {
  return get<Result<Announcement>>(`/announcements/${id}`)
}

// 添加公告
export function addAnnouncement(data: Partial<Announcement>): Promise<Result<null>> {
  return postFormData<Result<null>>('/announcements/add', data)
}

// 更新公告
export function updateAnnouncement(data: Partial<Announcement>): Promise<Result<null>> {
  return postFormData<Result<null>>('/announcements/update', data)
}

// 删除公告
export function deleteAnnouncement(id: number): Promise<Result<null>> {
  return del<Result<null>>(`/announcements/deleted/${id}`)
}

// 上传文件
export function uploadFile(data: FormData): Promise<Result<string>> {
  return postFormData<Result<string>>('/files/upload', data)
}

export function downloadFiles(path: string): Promise<Result<null>>{
  return get<Result<null>>(`/files/download?path=${path}`,null)
}
